package com.gdpu.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gdpu.bean.Goods;
import com.gdpu.bean.Outdingdan;
import com.gdpu.mapper.GoodsMapper;
import com.gdpu.mapper.OutdingdanMapper;
import com.gdpu.service.OutdingdanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gdpu.vo.OutdingdanVo;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class OutdingdanServiceImpl extends ServiceImpl<OutdingdanMapper, Outdingdan> implements OutdingdanService {

    @Resource
    private OutdingdanMapper outdingdanMapper;

    @Resource
    private GoodsMapper goodsMapper;
    @Override
    public List<OutdingdanVo> voList() {
        List<Outdingdan> outdingdanList = this.outdingdanMapper.selectList(null);
        OutdingdanVo outdingdanVo = null;
        List<OutdingdanVo> result = new ArrayList<>();
        for (Outdingdan outdingdan : outdingdanList) {
            outdingdanVo = new OutdingdanVo();
            BeanUtil.copyProperties(outdingdan,outdingdanVo);
            QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("goods_id", outdingdan.getGoodsId());
            Goods goods = this.goodsMapper.selectOne(queryWrapper); //将条件传入就能拿到一个组织信息
            outdingdanVo.setGoodsName(goods.getName());
            outdingdanVo.setPrice(goods.getPrice());
            outdingdanVo.setPackages(goods.getPackages());
            outdingdanVo.setSize(goods.getSize());
            result.add(outdingdanVo);
        }
        return result;
    }
}
